package com.example.demo;

import com.example.demo.jpa.service.UserService;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author lyc
 * @date 2019/7/2.
 */
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("helloWorld");

            ArrayList<Integer> arrayList = new ArrayList<Integer>();
            arrayList.add(1);
            arrayList.add(3);
            arrayList.add(2);
            arrayList.add(4);
// 对list内的数据进行运算--加法
            Stream integerStreamSum = arrayList.stream();
            int value = arrayList.stream().reduce(0, (sum,item)->sum + item);
        System.out.println(value);
           arrayList.stream().reduce(0,(sum,item)->sum + item);
           /* Optional optionalSum = integerStreamSum.reduce((a,b)->a+b);
            if (optionalSum.isPresent()) {
                System.out.println(optionalSum.get());
            }
//或者
            Stream integerStreamSumOther = arrayList.stream();
            Integer sum = integerStreamSumOther.reduce(0, (a, b) -> a + b);
            System.out.println(sum);
// 对list内的数据进行运算--乘法
            Stream integerStreamMul = arrayList.stream();
            Optional optionalMul = integerStreamMul.reduce((a, b) -> a * b);
            if (optionalMul.isPresent()) {
                System.out.println(optionalMul.get());
            }
//或者
            Stream optionalMulOther = arrayList.stream();
            Integer mul = optionalMulOther.reduce(1, (a, b) -> a * b);
            System.out.println(mul);*/
        test01();

        }



        public static void test01(){

            LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
            Method[] methods = UserService.class.getDeclaredMethods();
            //String methodName = "list";
            for (int i = 0; i <methods.length ; i++)

            {
               // if (methodName.equals(methods[i].getName())) {
                    String[] parames = u.getParameterNames(methods[i]);
                Parameter[] parameters = methods[i].getParameters();
                for (Parameter parameter:parameters) {
                    System.out.println(parameter.getName());
                }
                    System.out.println(Arrays.asList(parames));
               // }
            }
        }

}

